package com.ai.dylan.spring.mcp.repository;


import com.ai.dylan.spring.mcp.entity.BookInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookRepository extends JpaRepository<BookInfo, Long> {

  // 根据书名模糊查询
  @Query("SELECT b FROM BookInfo b WHERE LOWER(b.title) LIKE LOWER(CONCAT('%', :title, '%'))")
  List<BookInfo> findByTitle(@Param("title") String title);

  // 根据作者查询
  @Query("SELECT b FROM BookInfo b WHERE LOWER(b.author) LIKE LOWER(CONCAT('%', :author, '%'))")
  List<BookInfo> findByAuthor(String author);
  @Query("SELECT b FROM BookInfo b WHERE LOWER(b.category) LIKE LOWER(CONCAT('%', :category, '%'))")
  // 根据分类查询
  List<BookInfo> findByCategory(String category);
}
